<!--
 * @Author: your name
 * @Date: 2021-10-25 14:42:44
 * @LastEditTime: 2021-10-25 15:09:48
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /a1902-a-group/index.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" name="" id="input">
    <div id="values"></div>
    
    <input type="text" name="" id="ages">
    <div id="agevalue"></div>
</body>
<script>
    let obj = {name: '123', age: '345'};
    
    obj = new Proxy(obj, {
        get: (target, prop) => {
            return target[prop];
        },
        set: (target, prop, value) => {
            target[prop] = value;
            observer();
        }
    })

    obj.age = '哈哈哈哈'

    function observer () {
        console.log(obj)
        input.value = obj.name;
        values.innerHTML = obj.name;
        agevalue.innerHTML = obj.age;
    }


    input.oninput = function() {
        console.log(this.value)
        obj.name = this.value;
    }

    ages.oninput = function() {
        obj.age = this.value;
    }
</script>
</html>